package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.service.HealthAccessService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("HealthAccess")
public class HealthAccessController {

    @Reference
    HealthAccessService healthAccessService;

    @RequestMapping("findByPage")
    public PageResult findByPage(@RequestBody QueryPageBean queryPageBean){
        PageResult byPage = healthAccessService.findByPage(queryPageBean);
        return byPage;
    }

    @RequestMapping("addAccess")
    public Result addAccess(@RequestBody Map map, int id){

        try {
            healthAccessService.addAccess(map,id);
            return new Result(true, MessageConstant.ADD_HEALTH_ACCESS_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, MessageConstant.ADD_HEALTH_ACCESS_FAIL);
        }
    }


    @RequestMapping("checkAccess")
    public Result checkAccess(int id){

        try {
            Map map=healthAccessService.CheckAccess(id);
            return new Result(true, MessageConstant.ADD_HEALTH_ACCESS_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, MessageConstant.ADD_HEALTH_ACCESS_FAIL);
        }
    }


    @RequestMapping("del")
    public Result del(int id){

        try {
            healthAccessService.del(id);
            return new Result(true, MessageConstant.DEL_ACCESS_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.DEL_ACCESS_FAIL);
        }
    }
}
